package com.wisdom.admin.controller;

import com.wisdom.admin.common.api.CommonResult;
import com.wisdom.admin.service.PolyLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ming
 * @ClassName ApisController.java
 * @Description 聚合接口
 * @createTime 2021年03月30日 13:38:00
 */
@RequestMapping(value = "/apis")
@Api(tags = "ApisController",description = "聚合接口")
@Controller
public class ApisController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ApisController.class);

    @Autowired
    PolyLocationService locationService;

    @ApiOperation("根据经纬度获取位置信息")
    @RequestMapping(value = "/location",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getLocation(@RequestParam("longitude") String longitude,
                                    @RequestParam("latitude") String latitude)
    {
        if (latitude == null || longitude == null){
            return CommonResult.failed("latitude或longitude参数为空");
        }
        Map result = locationService.getLocation(longitude,latitude);
        return CommonResult.success(result);
    }

    @ApiOperation("获取时间")
    @RequestMapping(value = "/time",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getTime()
    {
        long stamp = 1535091681L;//设置你的时间
        final Date date = new Date(stamp);//新建一个时间对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//你要转换成的时间格式,大小写不要变
        final String time = sdf.format(date);//转换你的时间
        Map<String,Object> data = new HashMap<>();
        data.put("stamp",stamp);
        data.put("time",time);
        return CommonResult.success(data);
    }
}
